package com.train.sort;

public class BubbleSort {
    public static void main(String[] args) {
         //int[] arr={3,9,-1,10,-2};
        int[] arr={1,3,2,4,5};
         int temp,count=0;
         boolean flag=false;
         for (int i=0;i<arr.length-1;i++)
         {
             for (int j=0;j<arr.length-1-i;j++)
             {
                 if (arr[j]>arr[j+1])
                 {
                     flag=true;
                     temp=arr[j];
                     arr[j]=arr[j+1];
                     arr[j+1]=temp;
                 }
             }
             if (flag)
             {
                 flag=false;
             }else {
                 break;
             }
             count++;
         }

         for (int i=0;i<arr.length;i++)
         {
             System.out.print(arr[i]+" ");
         }
        System.out.println(count);
    }
}
